package com.atguigu.stgy.admin.controller;

import com.atguigu.stgy.admin.service.SystemUserService;
import com.atguigu.stgy.model.dto.SystemUserLoginDTO;
import com.atguigu.stgy.model.entity.SystemUser;
import com.atguigu.stgy.model.result.R;
import com.atguigu.stgy.model.vo.CaptchaVO;
import com.atguigu.stgy.model.vo.SystemUserInfoVO;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin")
public class SystemUserLoginController {

    @Resource
    SystemUserService systemUserService;
    ///admin/info
    @GetMapping("info")
    public R userInfo(@RequestHeader("access_token")String token){
        //前端登录成功 会在请求头中通过access_token 携带jwt字符串 到后端
        SystemUserInfoVO systemUserInfoVO = systemUserService.getUserInfo(token);
        return R.ok(systemUserInfoVO);
    }
    @PostMapping("/login")
    public R login(@RequestBody SystemUserLoginDTO loginDTO){
        String token  = systemUserService.login(loginDTO);
        //登录成功返回jwt字符串
        return R.ok(token);
    }
    @GetMapping("/login/captcha")
    public R captcha(){
        CaptchaVO captchaVO = systemUserService.generateCaptcha();
        return R.ok(captchaVO);
    }
}
